package cn.smbms.service;

import java.io.File;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mysql.jdbc.StringUtils;

import cn.pojo.User;
import cn.smbms.dao.UserDao;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	public UserDao userDao;

	@Override
	public List<User> UserList(String name, Integer role, int index) {
		return userDao.UserList(name, role, index);
	}

	@Override
	public User login(String code, String pwd) {
		return userDao.login(code, pwd);
	}

	@Override
	public User userCode(String code) {
		return userDao.userCode(code);
	}

	@Override
	public Integer getCount(String name, Integer role) {
		return userDao.getCount(name, role);
	}

	@Override
	public int useradd(User user) {
		return userDao.useradd(user);
	}

	@Override
	public int userUp(User user) {
		return userDao.userUp(user);
	}

	@Override
	public User getById(String id) {
		return userDao.getById(id);
	}

	@Override
	public int pwdUp(String code, String pwd) {
		return userDao.pwdUp(code, pwd);
	}

	@Override
	public int delById(String id) {
		String path = userDao.getById(id).getIdPicPath();
		if (!StringUtils.isNullOrEmpty(path)) {
			int num=path.lastIndexOf("\\");
			String name=path.substring(num+1);
			File file=new File("D:\\Program Files\\bdqn\\Y2\\EclipseWorkspace\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\ch10_2\\statics\\uploadFile\\"+name);
			file.delete();
		}
		return userDao.delById(id);
	}

}
